/***********************************************************************
 * Module:  VehicleGroupController.java
 * Author:  Administrator
 * Purpose: Defines the Class VehicleController
 ***********************************************************************/

package ishitong.vehicleManagement.controller;

import ishitong.vehicle.common.model.VehicleGroup;
import ishitong.common.Constants;
import ishitong.common.model.SysCode;
import ishitong.commons.pagination.Pagination;
import ishitong.commons.pagination.PaginationResult;
import ishitong.vehicle.common.service.biz.VehicleGroupService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/** @pdOid cf113b29-04ae-4ced-91e9-d90e758ade30 */
@Controller
public class VehicleGroupController extends ishitong.common.controller.ActionController {
   /** @pdOid 4dd5edc1-779c-46fa-996e-1939d09cf77e */
   private static final String VCG_SLT_DLG = "vehicleManagement/vehicleGroup/vehicleGroupSearch";
   /** @pdOid 08d0fac0-6b58-451b-b4ad-d30411d70919 */
   private static final String VCG_SLT_LST = "vehicleManagement/vehicleGroup/vehicleGroupSearchList";
   /** @pdOid d1efdcde-2780-4f2d-9506-f2568a21de61 */
   private static final String VCG_EDT = "vehicleManagement/vehicleGroup/vehicleGroupEdit";
   /** @pdOid 35bf483c-4e86-4f6f-a24b-5a40268a33c3 */
   private static final String VCG_VIW = "vehicleManagement/vehicleGroup/vehicleGroupView";
   /** @pdOid d5c1de36-fd95-4cc6-8e45-a2a22621f0d0 */
   @Autowired
   private VehicleGroupService vehicleGroupService;
   
   /** @param request
    * @pdOid a8e3a288-a8a2-469c-845d-e5bb9039cc40 */
   @RequestMapping(value = "/showVehicleGroupSearch.do")
   public ModelAndView handleShowVehicleGroupSearch(HttpServletRequest request) {
   	return new ModelAndView(VCG_SLT_DLG);
   }
   
   /** @param request 
    * @param vehicleGroup 
    * @param pagination
    * @exception Exception
    * @pdOid 1669d601-865c-4db5-b039-b50aa7a9e73e */
   @RequestMapping(value = "/ajaxVehicleGroupSearchList.do",method = RequestMethod.POST)
   public ModelAndView handleAjaxFindVehicleGroupSelectList(HttpServletRequest request, VehicleGroup vehicleGroup, Pagination pagination) throws Exception {
   	try {
   		Map<String, Object> model = new HashMap<>();
   		vehicleGroup.setDeleteflag(Constants.DELETE_FLAG_NOT);
   		PaginationResult<VehicleGroup> listVehicleGroup = vehicleGroupService.queryForPage(vehicleGroup, pagination);   		
   		model.put("listVehicleGroup", listVehicleGroup);
   		return new ModelAndView(VCG_SLT_LST, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param vehicleGroup 
    * @param response
    * @exception Exception
    * @pdOid 1895290d-0c60-46bb-b588-3efbda5b86e8 */
   @RequestMapping(value = "/ajaxShowVehicleGroupEdit.do",method = RequestMethod.POST)
   public ModelAndView handleAjaxShowVehicleGroupEdit(HttpServletRequest request, VehicleGroup vehicleGroup, HttpServletResponse response) throws Exception {
   	try {
   		Map<String, Object> model = new HashMap<String, Object>();
   		if(vehicleGroup.getId() != null){
   			//需要getbyid
   			List<VehicleGroup> listVehicleGroup = vehicleGroupService.getVehicleGroupByCondition(vehicleGroup);
   			vehicleGroup = listVehicleGroup.get(0);
   			model.put("vehicleGroup", vehicleGroup);
   			//号牌种类
   			List<SysCode> lstPlatetypes = spiSysCodeService.getSysCodeListByIds(vehicleGroup.getPlatetypes());
   			model.put("lstPlatetypes", lstPlatetypes);
   			//车辆类型
   			List<SysCode> lstVehicleType = spiSysCodeService.getSysCodeListByIds(vehicleGroup.getVehicletypes());
   			model.put("lstVehicleType", lstVehicleType);
   			//车辆分类
   			List<SysCode> lstVehicleClassification = spiSysCodeService.getSysCodeListByIds(vehicleGroup.getVehicleclassifications());
   			model.put("lstVehicleClassification", lstVehicleClassification);
   			//使用性质
   			List<SysCode> lstUseNature = spiSysCodeService.getSysCodeListByIds(vehicleGroup.getVehicleusingcharacters());
   			model.put("lstUseNature", lstUseNature);
   		}
   		return new ModelAndView(VCG_EDT, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param vehicleGroup
    * @exception Exception
    * @pdOid b24dd869-d620-401d-9fe3-aa9232c9fa8e */
   @RequestMapping(value = "/ajaxShowVehicleGroupView.do",method = RequestMethod.POST)
   public ModelAndView handleAjaxShowVehicleGroupView(HttpServletRequest request, VehicleGroup vehicleGroup) throws Exception {
   	try {
   		Map<String, Object> model = new HashMap<String, Object>();
   		if(vehicleGroup.getId() != null){
   			//需要getbyid
   			List<VehicleGroup> listVehicleGroup = vehicleGroupService.getVehicleGroupByCondition(vehicleGroup);
   			vehicleGroup = listVehicleGroup.get(0);
   			model.put("vehicleGroup", vehicleGroup);
   			//号牌种类
   			List<SysCode> lstPlatetypes = spiSysCodeService.getSysCodeListByIds(vehicleGroup.getPlatetypes());
   			model.put("lstPlatetypes", lstPlatetypes);
   			//车辆类型
   			List<SysCode> lstVehicleType = spiSysCodeService.getSysCodeListByIds(vehicleGroup.getVehicletypes());
   			model.put("lstVehicleType", lstVehicleType);
   			//车辆分类
   			List<SysCode> lstVehicleClassification = spiSysCodeService.getSysCodeListByIds(vehicleGroup.getVehicleclassifications());
   			model.put("lstVehicleClassification", lstVehicleClassification);
   			//使用性质
   			List<SysCode> lstUseNature = spiSysCodeService.getSysCodeListByIds(vehicleGroup.getVehicleusingcharacters());
   			model.put("lstUseNature", lstUseNature);
   		}
   		return new ModelAndView(VCG_VIW, model);
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   	return null;
   }
   
   /** @param request 
    * @param response 
    * @param vehicleGroup
    * @exception Exception
    * @pdOid 95c12a16-3381-4a78-bad1-769ca0d5bdfb */
   @RequestMapping(value = "/ajaxSaveVehicleGroup.do",method = RequestMethod.POST)
   public void handleAjaxSaveVehicleGroup(HttpServletRequest request, HttpServletResponse response, VehicleGroup vehicleGroup) throws Exception {
   	try {
   		if(vehicleGroup.getId() != null){
   			vehicleGroupService.modifyVehicleGroup(vehicleGroup);
   		} else {
   			vehicleGroupService.addVehicleGroup(vehicleGroup);
   		}
   	} catch (Exception e) {
   		e.printStackTrace();
   	}
   }
   
   /** @param request 
    * @param vehicleGroupIds 
    * @param response
    * @exception Exception
    * @pdOid 77d54760-ae08-49de-a241-a41245668116 */
   @RequestMapping(value = "/ajaxDeleteVehicleGroupByIds.do",method = RequestMethod.POST)
   public void handleAjaxDeleteVehicleGroupByIds(HttpServletRequest request, long vehicleGroupIds, HttpServletResponse response) throws Exception {
   	try {
   		vehicleGroupService.deleteVehicleGroupById(vehicleGroupIds);
   	} catch (Exception e) { 		
   		e.printStackTrace();
   	} 	
   }

}